package mount

import (
	"go.uber.org/zap"
	"sync"
	"virus-proxy/internal/logger"
)

// MountSlice stores the mapping between NAS and mount points
type MountSlice struct {
	Drives     []string
	Mutex      sync.RWMutex
	DriversMap map[string]string
}

const (
	MountNum    = 26
	MinMountNum = 10 // windows给用户留A-J盘,这几个盘不能被挂载
)

// MountSliceIns Initialize global map
var MountSliceIns = &MountSlice{
	Drives:     make([]string, MountNum), // Index 0 -> A:, 1 -> B:, ..., 25 -> Z:
	DriversMap: map[string]string{},
	Mutex:      sync.RWMutex{},
}

func UpdateMount() error {
	output, err := ListMount()
	if err != nil {
		logger.LogError("List mount failed. ", zap.Error(err))
		return err
	}
	MountSliceIns.Mutex.Lock()
	defer MountSliceIns.Mutex.Unlock()
	DO.ParseDf(output)
	return nil
}
